package c.e.a.b.e.c;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import java.util.HashMap;
import java.util.TreeMap;

/* compiled from: com.google.android.gms:play-services-measurement-impl@@18.0.0 */
public final /* synthetic */ class g2 implements d2 {
    public final c2 a;
    public final String b;

    public g2(c2 c2Var, String str) {
        this.a = c2Var;
        this.b = str;
    }

    public final Object q() {
        Object obj;
        c2 c2Var = this.a;
        Object obj2 = this.b;
        ContentResolver contentResolver = c2Var.a.getContentResolver();
        Uri uri = u1.a;
        synchronized (u1.class) {
            if (u1.f == null) {
                u1.e.set(false);
                u1.f = new HashMap();
                u1.k = new Object();
                u1.l = false;
                contentResolver.registerContentObserver(u1.a, true, new t1());
            } else if (u1.e.getAndSet(false)) {
                u1.f.clear();
                u1.g.clear();
                u1.h.clear();
                u1.i.clear();
                u1.j.clear();
                u1.k = new Object();
                u1.l = false;
            }
            Object obj3 = u1.k;
            obj = null;
            String str;
            if (u1.f.containsKey(obj2)) {
                str = (String) u1.f.get(obj2);
                if (str != null) {
                    obj = str;
                }
            } else {
                String[] strArr = u1.m;
                int length = strArr.length;
                int i = 0;
                while (i < length) {
                    if (obj2.startsWith(strArr[i])) {
                        if (!u1.l || u1.f.isEmpty()) {
                            String[] strArr2 = u1.m;
                            HashMap hashMap = u1.f;
                            Cursor query = contentResolver.query(u1.b, null, null, strArr2, null);
                            TreeMap treeMap = new TreeMap();
                            if (query != null) {
                                while (query.moveToNext()) {
                                    try {
                                        treeMap.put(query.getString(0), query.getString(1));
                                    } finally {
                                        query.close();
                                    }
                                }
                            }
                            hashMap.putAll(treeMap);
                            u1.l = true;
                            if (u1.f.containsKey(obj2)) {
                                str = (String) u1.f.get(obj2);
                                if (str != null) {
                                    obj = str;
                                }
                            }
                        }
                    } else {
                        i++;
                    }
                }
                Cursor query2 = contentResolver.query(u1.a, null, null, new String[]{obj2}, null);
                if (query2 != null) {
                    try {
                        if (query2.moveToFirst()) {
                            String string = query2.getString(1);
                            if (string != null && string.equals(null)) {
                                string = null;
                            }
                            u1.a(obj3, obj2, string);
                            if (string != null) {
                                obj = string;
                            }
                            query2.close();
                        } else {
                            u1.a(obj3, obj2, null);
                        }
                    } finally {
                        query2.close();
                    }
                } else if (query2 != null) {
                    query2.close();
                }
            }
        }
        return obj;
    }
}
